<template>
	<view class="container">
		<view class="person-info">
			<view class="icon-container" v-if="salaryFlowInfo.avatar && !loading">
				<!-- <preview-image previewClass="avatar" :avatar="salaryFlowInfo.avatar" class="avatar-container"></preview-image> -->
				<image :src="salaryFlowInfo.avatarData" class="avatar" @tap="previewImage(salaryFlowInfo.avatarData)"></image>
			</view>
			<view :class="'icon-container ' + (salaryFlowInfo.personType != '10' ? 'orange' : 'green')" v-else-if="!salaryFlowInfo.avatar && !loading">
				<icon type="icon-a-laowurenyuan1x" :size="82" v-if="salaryFlowInfo.personType != '10'" />
				<icon type="icon-a-guanlirenyuan1x" :size="82" v-else />
			</view>
			<view class="icon-container" v-else></view>
			<view class="info-detail-container">
				<view class="info-detail-top">
					<text class="person-name">{{ salaryFlowInfo.name }}</text>
					<text class="work-type">{{ salaryFlowInfo.workTypeName }}</text>
				</view>
				<view class="info-detail-bottom">{{ salaryFlowInfo.orgName }}</view>
			</view>
		</view>
		<view class="choose-date">
			<picker mode="date" fields="year" :value="salaryFlowInfo.year" @change="changeDate">
				<view class="date-container">
					<text class="date-content">{{ salaryFlowInfo.year }}年</text>
					<icon type="icon-riqi2" :size="42" />
				</view>
			</picker>
		</view>
		<scroll-view
			class="scroll-view"
			scroll-y
			:show-scrollbar="false"
			enhanced
			scroll-with-animation
			enable-passive
			fast-deceleration
			:bounces="false"
			refresher-enabled
			:refresher-triggered="isPullRefresh"
			@refresherrefresh="refreshList"
			enable-flex
		>
			<view class="record-list" v-if="salaryFlowInfo.salaryDetailList.length != 0">
				<view class="record" v-for="(item, index) in salaryFlowInfo.salaryDetailList" :key="index">
					<view class="record-title">账期：{{ item.date }}</view>

					<view class="record-content-container">
						<view class="content-item">
							<text class="item-label">应发金额：</text>
							<text class="item-content">{{ item.totalPayAmount }}</text>
						</view>
						<view class="content-item">
							<text class="item-label">实发金额：</text>
							<text class="item-content">{{ item.finalPayingAmount }}</text>
						</view>
					</view>

					<view class="record-content-container">
						<view class="content-item">
							<text class="item-label">借支预支金额：</text>
							<text class="item-content">{{ item.borrowingsAndAdvancesAmount }}</text>
						</view>
						<view class="content-item">
							<text class="item-label">代缴款：</text>
							<text class="item-content">{{ item.remittingAmount }}</text>
						</view>
					</view>

					<view class="record-content-container">
						<view class="content-item">
							<text class="item-label">代扣款：</text>
							<text class="item-content">{{ item.withholdingAmount }}</text>
						</view>
						<view class="content-item">
							<text class="item-label">实得金额：</text>
							<text class="item-content">{{ item.actualAmount }}</text>
						</view>
					</view>
				</view>
				<view class="no-more">没有更多了</view>
			</view>
			<view class="no-data-container" v-else>
				<no-data></no-data>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import { common } from '@/pagesA/utils/common.js';
import noData from '@/pagesA/components/common/no-data/no-data';
const app = getApp();
export default {
	components: {
		noData
	},
	data() {
		return {
			loading: false,
			isPullRefresh: false,
			date: ''
		};
	},
	props: {
		salaryFlowInfo: {
			type: Object,
			default: () => ({})
		}
	},
	methods: {
		previewImage(avatar) {
			let urls = [avatar];
			if (avatar.indexOf('http') < 0 && avatar.indexOf('https') < 0) {
				return;
			}
			uni.previewImage({
				current: avatar,
				urls,
				complete: () => {
					app.globalData.isPreview = true;
				}
			});
		},
		changeDate(e) {
			const date = e.detail.value;
			// this.setData({
			// 	date
			// });
			this.date = date;
			this.$emit('getlist', {
				detail: {
					year: date
				}
			});
		},
		refreshList() {
			this.isPullRefresh = true;
			this.$emit('refreshlist', {
				detail: {
					year: this.date
				}
			});
		}
	},
	created: function () {},
	watch: {
		salaryFlowInfo: {
			handler: function (value) {
				if (value.loading) {
					this.loading = false;
				}
				// this.setData({
				// 	loading: this.loading,
				// 	isPullRefresh: this.isPullRefresh,
				// 	date: value.year
				// });
				this.isPullRefresh = value.isPullRefresh;
				this.date = value.year;
			},
			immediate: true,
			deep: true
		}
	}
};
</script>
<style>
.container {
	width: 100vw;
	height: 100%;
	background-color: #f6f7fa;
	display: flex;
	flex-direction: column;
}

.person-info {
	display: flex;
	align-items: center;
	background-color: #fff;
	padding: 32rpx;
	margin-bottom: 24rpx;
}

.person-info .icon-container {
	width: 100rpx;
	height: 100rpx;
	border-radius: 16rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
}

.icon-container .avatar-container {
	width: 100rpx;
	height: 100rpx;
	border-radius: 12rpx;
	background-color: transparent;
}

.icon-container.green {
	background-color: #00c467;
}

.icon-container.orange {
	background-color: #ff9544;
}

.person-info .avatar {
	width: 96rpx;
	height: 96rpx;
	border-radius: 12rpx;
	border: 1rpx solid #c8d1ed;
}

.person-info .info-detail-container {
	margin-left: 24rpx;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
}

.info-detail-container .info-detail-top {
	display: flex;
	align-items: center;
}

.info-detail-top .person-name {
	font-size: 34rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 550;
	color: #1e253f;
	word-break: break-all;
	text-align: justify;
}

.info-detail-top .work-type {
	flex-shrink: 0;
	flex-wrap: wrap;
	max-width: 380rpx;
	background: #eff1f6;
	border-radius: 6rpx;
	padding: 4rpx 16rpx;
	font-size: 24rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 550;
	color: #4b5680;
	margin-left: 16rpx;
	display: flex;
	align-items: center;
	margin-bottom: 4rpx;
	text-align: justify;
	word-break: break-all;
}

.info-detail-bottom {
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #949dbf;
}

.choose-date {
	margin: 0 24rpx 24rpx;
	border: 1rpx solid #b0aebf;
	border-radius: 8rpx;
	padding: 12rpx 12rpx 12rpx 24rpx;
}

.choose-date .date-container {
	display: flex;
	align-items: center;
	justify-content: space-between;
	font-size: 28rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 550;
	color: #4b5680;
}

.scroll-view {
	flex: 1;
	height: 0;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
}

.record-list {
	margin: 0 24rpx;
}

.record-list .record {
	background: #ffffff;
	border-radius: 16rpx;
	padding: 32rpx;
	margin-bottom: 24rpx;
}

.record .record-title {
	font-size: 32rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 550;
	color: #1e253f;
}

.record .record-content-container {
	margin-top: 24rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.record-content-container .content-item {
	display: flex;
	align-items: center;
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
}

.content-item .item-label {
	color: #1e253f;
}

.content-item .item-content {
	color: #4b5680;
}

.no-more {
	font-size: 26rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #949dbf;
	text-align: center;
	padding-bottom: 24rpx;
}

.no-data-container {
	height: 100%;
}
</style>
